/*
 * @Author: 晟松
 * @Date: 2021-12-07 20:25:57
 * @LastEditors: 晟松
 * @LastEditTime: 2022-02-04 20:49:02
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\model\Resident.js
 * @Description: 居民
 */
import Sequelize from "sequelize";
import { isValidateEnum } from "@main/util/ValidateUtil";
import { ParamError } from "../common/CommonError";
import enums from "@main/config/enums";

export const modelName = "resident";

const DataTypes = Sequelize.DataTypes;

export const attributes = {
    identity: {
        type: DataTypes.INTEGER,
        validate:{
            check(val){
                if( val!=enums['identity']['resident']){
                    throw new ParamError(`identity resident: ${val}值错误`);
                }
            }
        }
    },
    userName: {
        type: DataTypes.STRING,
    },
    avatar: {
        type: DataTypes.STRING,
    },
    gender: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (!isValidateEnum(val, "gender")) {
                    throw new ParamError(`gender: ${val}值错误`);
                }
            },
        },
    },
    age: {
        type: DataTypes.INTEGER,
        validate: {
            isAge(val) {
                if (val < 20 || val > 100) {
                    throw new ParamError(`年龄限制在 20-100 `);
                }
            },
        },
    },
    specialDescription: DataTypes.STRING,
    communityName: DataTypes.STRING,
    detailedAddress: DataTypes.STRING, // 详细地址
    available: DataTypes.BOOLEAN, // 是否被居委会审核通过，即是否可用
    timeIntegral: DataTypes.INTEGER, // 时间积分数
    // 这两个是关于区块链的一个记录，主要是记录其中的交易hash和块hash，通过这两个hash就可从区块链中获取到对应的信息
    transactionHash: DataTypes.STRING,
    blockHash: DataTypes.STRING,
};

export const options = {
    // tableName: "t_user_reference",
};
